package com.project.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.po.User;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @ProjectName:
 * @Package:
 * @ClassName:
 * @Author: ZhaoLongShi
 * @CreateDate:
 */
@SuppressWarnings("all")
public interface UserMapper extends BaseMapper<User> {
    /**
     * 检查用户名是否存在(登录)
     *
     * @param username
     * @return
     */
    default User selectUserByName(String username) {
        QueryWrapper<User> qw = new QueryWrapper();
        qw.lambda().eq(User::getUsername, username);
        return this.selectOne(qw);
    }

    Double getDiscout(Long id);

    /**
     * 检查用户名或手机号是否被注册
     *
     * @param username
     * @param phone
     * @return
     */
    default User checkNameAndPhone(String username, Long phone) {
        QueryWrapper<User> qw = new QueryWrapper();
        qw.lambda().eq(User::getUsername, username).or().eq(User::getPhone, phone);
        return this.selectOne(qw);
    }

    /**
     * 检查手机号是否存在(登录)
     *
     * @param phone
     * @return
     */
    default User selectUserByPhone(Long phone) {
        QueryWrapper<User> qw = new QueryWrapper();
        qw.lambda().eq(User::getPhone, phone);
        return this.selectOne(qw);
    }

    /**
     * 检查原密码是否正确
     *
     * @param userId
     * @param password
     * @return
     */
    User checkPassword(Long userId, String password);

    /**
     * 检查是否为会员
     *
     * @param userId
     * @return 返回1是会员，其他不是
     */
    Long isVip(Long userId);

    /**
     * 根据手机号获取用户id
     *
     * @param phone
     * @return
     */
    Long getUserId(Long phone);

    /**
     * 查询所有用户(分页)
     *
     * @return
     */
    default Page<User> selectAllUser(int current) {
        Page<User> userPage = new Page<>(current, 3);
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.lambda().eq(User::getIsDel, 1);
        return this.selectPage(userPage, qw);
    }

    /**
     * 根据用户ID删除用户
     *
     * @param isList
     * @return
     */
    int deleteUserByIds(List<Long> isList);

    /**
     * 充值到余额
     *
     * @param price
     * @return
     */
    int rechargeToBalance(@Param("userId") Long userId,@Param("price") double price);
}